package com.twu.biblioteca;

public class MainState implements State {

    String menuLabel = "Main Menu";

    public static State getInstance(){
        if (instance == null){
            instance = new MainState();
        }

        return instance;
    }

    private static MainState instance;

    public State[] menuStates = new State[] {ExitState.getInstance(), ListState.getInstance(), ReserveState.getInstance()};

    private MainState(){

    }

    public State[] getMenuStates() {
        return menuStates;
    }

    @Override
    public String getMenuLabel() {
        return menuLabel;
    }

    @Override
    public void setMenuLabel(String label) {
        menuLabel = label;
    }

    @Override
    public String[] getOptions() {
        return MenuGenerator.generate(instance);
    }

    @Override
    public State reactToInput(int input) {
        return getState(input);
    }

    private State getState(int input) {
        if (input >=0 && input < menuStates.length){
            return menuStates[input];
        }
        return InvalidOptionState.getInstance();
    }
}
